package com.tiamo.traders.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tiamo.traders.entity.Business;
import com.tiamo.traders.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tiamo/business")
public class BusinessController{

    @Autowired
    BusinessService businessService;

    @RequestMapping("/bussFindAll")
    public Map businessFindAll(Business business,@RequestParam Integer page,@RequestParam Integer limit){
        System.out.println(business);
        Map map=new HashMap();
        PageHelper.startPage(page,limit);
        List<Business> businessList=businessService.businessFindAll(business);
        PageInfo<Business> pageInfo=new PageInfo<Business>(businessList);
        int count=businessService.businessGetCount(business);
        map.put("data",pageInfo.getList());
        map.put("count",count);
//        System.out.println(businessList);
        return map;
    }

    @RequestMapping("/GetCount")
    public Integer businessGetCount(Business business){
        return businessService.businessGetCount(business);
    }

    @RequestMapping("/businessAdd")
    public Integer businessAdd(Business business) {
        return businessService.businessAdd(business);
    }

    @RequestMapping("/delete")
    public Integer businessDelete(@RequestParam Integer id) {
        return businessService.businessDelete(id);
    }

    @RequestMapping("/update")
    public Integer businessUpdate(Business business) {
        return businessService.businessUpdate(business);
    }

    @RequestMapping("/findById")
    public Business businessFindById(@RequestParam Integer id) {
        Business business=businessService.businessFindById(id);
        return business;
    }
}
